#include <iostream>
#include <opencv2/opencv.hpp>

#include "line_segment_detector.h"

int main() {
    std::cout << "Hello! Let's test Line Segment Detector Algorithm." << std::endl;

    unsigned char testImageData[256 * 192] = { 0 };

    FILE *fp0 = fopen("../line_segment_detector/data/image.dat", "rb");
    if (fp0) {
        fread(testImageData, sizeof(unsigned char), 256 * 192, fp0);
        fclose(fp0);
    }

    cv::Mat edgeImage(cv::Size(192, 256), CV_8UC1, testImageData);
    cv::imshow("edgeImage", edgeImage);

    clsd::CLSD lsd;
    auto lines = lsd.Detect(testImageData, 256, 192);

    cv::Mat showImage;
    cv::resize(edgeImage, showImage, cv::Size(0, 0), 2, 2, cv::INTER_LANCZOS4);
    cv::cvtColor(showImage, showImage, cv::COLOR_GRAY2BGR);

    for (auto& v : lines) {
        const cv::Point2f b(v[0] * 2, v[1] * 2);
        const cv::Point2f e(v[2] * 2, v[3] * 2);
        line(showImage, b, e, cv::Scalar(0, 0, 255), 2);
    }

    cv::imshow("showImage1", showImage);
    cv::waitKey(0);

    return 0;
}
